/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ocp.bundles.patients.impl;

import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.BundleActivator;


/**
 *
 * @author Paco Lopez Marmol
 */
public class Activator implements BundleActivator {
    
    public static BundleContext bc = null;
    
    private static String patientsNames[] = {
        "Maria",
        "Paco",
        "Pepe",
        "Antonio",
        "Jose",
        "Francisco",
        "Ana",
        "Antonio",
        "Tomas" 
    };
    
    private static Patient patients[] = null;

    public void start(BundleContext bc) throws Exception {
        
        System.out.println(bc.getBundle().getHeaders().get(
                        Constants.BUNDLE_NAME)
                        + " comienza...");
        Activator.bc = bc;
        
        patients = new Patient[patientsNames.length];
        for (int i = 0; i < patients.length ; i++ ){
            patients[i] = new Patient( patientsNames[i] , bc );
            patients[i].start();
        }        
        
    }

    public void stop(BundleContext bc) throws Exception {
        
        System.out.println(bc.getBundle().getHeaders().get(
                        Constants.BUNDLE_NAME)
                        + " termina...");

        for (int i = 0; i < patients.length; i++) {
            patients[i].stop();
            patients[i] = null;
        }
        
        Activator.bc = null;
      
    }
   

}
